using System;
using System.Drawing;
using System.Linq.Expressions;
using CloudShot.Editor.CanvasFigures;

namespace CloudShot.Utils.Tweens
{
  class RectangleAnimationAdapter<T> : AnimationAdapter where T : IBoundingBoxFigure
  {
    private Rectangle _rectBegin;
    private Rectangle _rectEnd;

    public override void SetValue(float value)
    {
      int x = (int)(_rectBegin.X + ((_rectEnd.X - _rectBegin.X) * value));
      int y = (int)(_rectBegin.Y + ((_rectEnd.Y - _rectBegin.Y) * value));
      int w = (int)(_rectBegin.Width + ((_rectEnd.Width - _rectBegin.Width) * value));
      int h = (int)(_rectBegin.Height + ((_rectEnd.Height - _rectBegin.Height) * value));

      PropertyInfo.SetValue(Target, new Rectangle(x, y, w, h), null);
    }

    public RectangleAnimationAdapter(T target, Expression<Func<T, Rectangle>> expression, Rectangle to)
      : base(target, expression.GetPropertyInfo(), 0, 1)
    {
      _rectBegin = (Rectangle)PropertyInfo.GetValue(target);
      _rectEnd = to;
    }

    public override string ToString()
    {
      return string.Format("Name = {0}, start = {1}, end = {2}", Name, _rectBegin, _rectEnd);
    }
  }
}